package com.kitty.game.pet.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.ServerService;
import com.kitty.game.difu.domin.GhostPeiYuanBasic;
import com.kitty.game.difu.domin.NingshenFieldAdd;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.equip.model.EquipField;
import com.kitty.game.fight.service.CountService;
import com.kitty.game.fuling.model.Fuling;
import com.kitty.game.item.service.PetStoneService;
import com.kitty.game.pet.service.BookService;
import com.kitty.game.pet.service.PetUtils;
import com.kitty.game.role.model.BasicAttrib;
import com.kitty.game.role.model.Role;
import com.kitty.game.skill.model.SkillBox;
import lombok.Getter;
import lombok.Setter;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.lang.Lang;
import org.nutz.lang.util.NutMap;

import java.util.*;

/**
 * 宠物
 */
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown =true)
public class Pet {
    private int id;

    @Comment("宠物主人")
    private int hostId;

    @Comment("宠物主人名称")
    private String hostName;

    @Comment("宠物名称")
    private String name;

    @Comment("宠物昵称")
    private String nickname;

    @Comment("面板ID")
    private String gid;

    @Comment("宠物头像")
    private short icon;
    @Comment("宠物时装")
    private int special_icon;

    @Comment("宠物类型")
    private byte type;

    @Comment("宠物或者坐骑")
    private byte itype;

    @Comment("宠物等级")
    private short level;

    @Comment("坐骑外观")
    private short rankItem;

    private long createtime;

//    /**
//     * 是否修复id
//     */
    private boolean repairedId;

    private byte position;//所在位置

    private short str;//力量

    private short dex;//敏捷

    private short wiz;//灵力

    private short con;//体质

    private short parry;//闪避

    private int currMana;//当前法力值

    private int currLife;//当前气血

    //战力
    @Comment("战力")
    private int fight_cap =0;

    @Comment("坐骑阶数")
    private byte rank;//

    @Comment("当前经验")
    private int exp;//

    @Comment("宠物相性")
    private byte polar;//

    @Comment("剩余属性")
    private short lastAtrrib;

    @Comment("基础血量成长")
    private short lifeEffect;//

    @Comment("基础法力成长")
    private short manaEffect;

    @Comment("基础物攻成长")
    private short phyEffect;

    @Comment("基础法攻成长")
    private short magEffect;

    @Comment("基础速度成长")
    private short speedEffect;

    @Comment("宠物亲密")
    private int intimacy;

    @Comment("宠物武学")
    private int martial;

    @Comment("宠物月武学")
    private int monthMartial;

    @Comment("宠物上月武学")
    private int prevMonthMartial;

    @Comment("宠物寿命")
    private int longevity = 16000;

    public void setLoyalty(int loyalty) {
        if(loyalty <0){
            loyalty=0;
        }
        this.loyalty =loyalty;
    }

    @Comment("宠物忠诚")
    private int loyalty = 100;

    @Comment("强化物攻")
    private int phyRebuildAdd;

    @Comment("强化物攻等级")
    private int phyRebuildLevel;

    @Comment("强化法攻")
    private int magRebuildAdd;

    @Comment("强化法攻等级")
    private int magRebuildLevel;

    @Comment("点化类型")
    private byte enchant;

    @Comment("当前点化灵气")
    private int enchant_v;

    @Comment("点化灵气最大值")
    private int enchant_k;

    @Comment("点化成长")
    private NutMap enchantEffect;

    @Comment("羽化类型")
    private byte eclosion;

    @Comment("羽化阶数")
    private byte eclosion_rank;

    @Comment("当前羽化灵气")
    private int eclosion_v;

    @Comment("羽化灵气最大值")
    private int eclosion_k;

    @Comment("羽化成长")
    private NutMap eclosionEffect;

    @Comment("剩余抗性点")
    private int lastResistPoint;

    @Comment("抗金")
    private int resistMetal;

    @Comment("抗木")
    private int resistWood;

    @Comment("抗水")
    private int resistWater;

    @Comment("抗火")
    private int resistFire;

    @Comment("抗土")
    private int resistEarth;

    @Comment("抗遗忘")
    private int resistForgotten;

    @Comment("抗中毒")
    private int resistPoison;

    @Comment("抗冰冻")
    private int resistFrozen;

    @Comment("抗昏睡")
    private int resistSleep;

    @Comment("抗混乱")
    private int resistConfusion;

    @Comment("锁定经验 1为锁定 0不锁定")
    private boolean lockexp;

    @Comment("飞升状态")
    private byte fly;

    @Comment("携带等级")
    private int reqLevel;

    @Comment("自动加点设置")
    private Map<String, Byte>  autoAtrrib;

    @Comment("自动战斗相关设置")
    private Map<String, Object> autoFightSet;

    @Comment("风灵丸时间")
    private int mountTime;

    @Comment("限制交易时间")
    private int limitTime;

    @Comment("洗练成长")
    private NutMap refineMap;

    @Comment("强化进度")
    private int magRebuildRate;

    @Comment("物攻强化进度")
    private int phyRebuildRate;

    @Comment("战斗喊话")
    private List<NutMap> shouts;

    @Comment("是否存入仓库")
    private boolean inStore;

    @Comment("是否注入彩凤之魂")
    private byte zhuru;

    private BasicAttrib basicAttrib = new BasicAttrib(1);

    private int phyPower;

    private int magPower;

    private int defense;

    private int speed;

    /**
     * 用于判断是否跟主人一个地图
     */
    private int mapId;

    //鬼宠 培元信息
    private int peiyuan_data_stage = 1;
    private int peiyuan_data_state;
    private int peiyuan_data_level;
    private int peiyuan_ghost_gas;

    /**
     * 增益属性值
     */
    private int extraSpeed;
    private int extraLife;
    private int extraMana;
    private int extraPhyPower;
    private int extraMagPower;
    private int extraDefense;

    /**
     * 天书增益属性值
     */
    private int bookExtraSpeed;
    private int bookExtraLife;
    private int bookExtraMana;
    private int bookExtraPhyPower;
    private int bookExtraMagPower;
    private int bookExtraDefense;
    /**
     * 增益属性点数
     */
    private int addattrNumber = 0;

//    // 培元增益属性
//    private int peiYuanSpeed;
//    private int peiYuanLife;
//    private int peiYuanMana;
//    private int peiYuanPower;
//    private int peiYuanMagPower;
//    private int peiYuanDefense;

    /*** 所有技能*/
    private SkillBox skillBox = new SkillBox();

    /**
     * 宠物妖石 位置对应妖石
     */
    private Set<PetStone> stones = new HashSet<>();

    @Comment("飞升成长")
    private NutMap flyEffect;


    @Comment("幻化成长")
    private HashMap<String, Integer> morphEffect = new HashMap<>();

    @Comment("共生成长")
    private HashMap<String, Integer> gongShengEffect = new HashMap<>();

    @Comment("共生对象")
    private String gongSheng_pet_id;

    //培元
    @Comment("培元加成")
    private Map<String, Integer> peiyuan_add_info = new HashMap<>();

    @Comment("培元当前加成")
    private Map<String, Integer> peiyuanCurrentInfo = new HashMap<>();
    @Comment("培元珠子展示")
    GhostPeiYuanBasic ghostPeiYuanBasic;
    @Comment("凝神加成")
    private List<NingshenFieldAdd> ningshenFieldAdds = new ArrayList<>();

    @JsonIgnore
    public short getTotalLifeEffect() {
        return (short) (lifeEffect
                + getEnchantEffect().getInt("life", 0)
                + getEclosionEffect().getInt("life", 0)
                + getFlyEffect().getInt("life", 0)
                + morphEffect.getOrDefault("life", 0)
                + gongShengEffect.getOrDefault("life", 0)
                + PetUtils.getEffect("life_effect",ningshenFieldAdds));
    }

    @JsonIgnore
    public short getTotalManaEffect() {
        return (short) (manaEffect
                + getEnchantEffect().getInt("mana", 0)
                + getEclosionEffect().getInt("mana", 0)
                + getFlyEffect().getInt("mana", 0)
                + morphEffect.getOrDefault("mana", 0)
        + gongShengEffect.getOrDefault("mana", 0)
                + PetUtils.getEffect("mana_effect",ningshenFieldAdds));
    }

    @JsonIgnore
    public short getTotalPhyEffect() {
        return (short) (phyRebuildAdd + phyEffect
                + getEnchantEffect().getInt("phy", 0)
                + getEclosionEffect().getInt("phy", 0)
                + getFlyEffect().getInt("phy", 0)
                + morphEffect.getOrDefault("phy", 0)
                + gongShengEffect.getOrDefault("phy", 0)
                + PetUtils.getEffect("mag_effect",ningshenFieldAdds));
    }

    @JsonIgnore
    public short getTotalMagEffect() {
        return (short) (magRebuildAdd + magEffect
                + getEnchantEffect().getInt("mag", 0)
                + getEclosionEffect().getInt("mag", 0)
                + getFlyEffect().getInt("mag", 0)
                + morphEffect.getOrDefault("mag", 0)
                + gongShengEffect.getOrDefault("mag", 0)
                + PetUtils.getEffect("phy_effect",ningshenFieldAdds));
    }

    @JsonIgnore
    public short getTotalSpeedEffect() {
        return (short) (speedEffect
                + getEnchantEffect().getInt("speed", 0)
                + getEclosionEffect().getInt("speed", 0)
                + getFlyEffect().getInt("speed", 0)
                + morphEffect.getOrDefault("speed", 0)
                + gongShengEffect.getOrDefault("speed", 0)
                + PetUtils.getEffect("speed_effect",ningshenFieldAdds));
    }


    /**
     * 进化的名字
     */
    private String evolveName;

    public void setBasicAttrib() {
        this.basicAttrib = new BasicAttrib(level);
    }


    public void setExp(int exp) {
        if (exp > 2000000000) {
            exp = 2000000000;
        } else if (exp < 0) {
            exp = 0;
        }
        if (exp>=SpringUtils.getRoleService().getPetUpgradeNeedExp(this.level)){
            try {
                throw new Exception();
            }catch (Exception e){
                String content = Lang.getStackTrace(e);
                if (!content.contains("GameServerStartup") && this.name !=null){
//                    LoggerFunction.ACTIVITY.getLogger().error("宠物经验溢出==={}", Lang.getStackTrace(e));
//                    LoggerFunction.ACTIVITY.getLogger().error("宠物经验溢出==={}==={}=={}", this.exp,exp,this.name);
                    this.exp= (int) (SpringUtils.getRoleService().getPetUpgradeNeedExp(this.level)-100);
                    return;
                }
            }
        }
        this.exp = exp;
    }

    @JsonIgnore
    public boolean isFly() {
        return fly == 1;
    }

    public boolean isRepairedId() {
        /*原注释*/
        if (ServerService.serverId != 1) {
            return true;//只修1服
        }
        return repairedId;
//        return false;
    }

    public void setRepairedId(boolean repairedId) {
        this.repairedId = repairedId;
    }/*原注释*/

    /**
     * 判断宠物是不是贵重宠物
     */
    @JsonIgnore
    public boolean isExpensive() {
        /**判断是否是神兽变异*/
        if (type == 3 || type == 4 || type == 6 || type == 7 || type == 8) {
            return true;
        }
        /**如果是6阶或以上的坐骑*/
        if ((itype == 1 || itype == 2) && rank >= 8) {
            return true;
        }
        if (phyRebuildLevel >= 5 || magRebuildLevel >= 5) {
            return true;
        }
        return false;
    }

    /**
     * 取宠物属性
     */
    @JsonIgnore
    public EquipField getFields() {
        this.setLastAtrrib(SpringUtils.getRoleService().getLastAttributePoint(this));/**修复宠物没有属性点*/
        this.setLastResistPoint(SpringUtils.getRoleService().getLastPolarPoint(this));

        Role role = SpringUtils.getPlayerService().getPlayerBy(SpringUtils.getPlayerService().getUidBy(this.getHostId()));
        SpringUtils.getBean(BookService.class).getBookExtra(role,this);
        EquipField basicField = new EquipField();
        basicField.setType((short) 1);
        ArrayList<FiedValue> list = new ArrayList<>();
        basicField.setFieldValues(list);
        CountService countService = SpringUtils.getBean(CountService.class);
//修改了等级
        list.add(new FiedValue(1, this.getNickname()));
        list.add(new FiedValue(6, this.getCurrLife()));
        list.add(new FiedValue(11, this.getCurrMana()));
        list.add(new FiedValue(31,3, this.getLevel() >= 194?194:this.getLevel()));//宠物最高等级？
        list.add(new FiedValue(109, this.getType()));
        list.add(new FiedValue(16, this.getLastAtrrib()));
        list.add(new FiedValue(44, this.getPolar()));
        list.add(new FiedValue(17, 0));
        list.add(new FiedValue(40, this.getIcon()));
        list.add(new FiedValue(41, 32768));
        list.add(new FiedValue(2, this.getStr() + this.getBasicAttrib().getStr()));
        list.add(new FiedValue(9, this.getWiz() + this.getBasicAttrib().getWiz()));
        list.add(new FiedValue(5, this.getCon() + this.getBasicAttrib().getCon()));
        list.add(new FiedValue(13, this.getDex() + this.getBasicAttrib().getDex()));
        int phyPower = countService.countPetMaxPhyPower(this);
        int magPower = countService.countPetMaxMagPower(this);
        int speed = countService.countPetMaxSpeed(this);
        int defense = countService.countPetMaxDefense(this);
        int maxLife = countService.countPetMaxLife(this);
        int maxMana = countService.countPetMaxMana(this);
        list.add(new FiedValue(7, maxLife));
        list.add(new FiedValue(12, maxMana));
        list.add(new FiedValue(3, phyPower));
        list.add(new FiedValue(10, magPower));
        list.add(new FiedValue(14, speed));
        list.add(new FiedValue(8, defense));
        list.add(new FiedValue(63, this.getIntimacy()));
        list.add(new FiedValue(25, this.getExp()));
        list.add(new FiedValue(65, this.getLastResistPoint()));
        list.add(new FiedValue(50, this.getResistMetal()));
        list.add(new FiedValue(51, this.getResistWood()));
        list.add(new FiedValue(52, this.getResistWater()));
        list.add(new FiedValue(53, this.getResistFire()));
        list.add(new FiedValue(54, this.getResistEarth()));
        list.add(new FiedValue(56, this.getResistPoison()));
        list.add(new FiedValue(57, this.getResistFrozen()));
        list.add(new FiedValue(58, this.getResistSleep()));
        list.add(new FiedValue(59, this.getResistForgotten()));
        list.add(new FiedValue(60, this.getResistConfusion()));
        list.add(new FiedValue(61, this.getLongevity()));
        list.add(new FiedValue(64, this.getMagEffect() - 40 + this.getManaEffect() - 40 + this.getSpeedEffect() - 40 + this.getPhyEffect() - 40 + this.getLifeEffect() - 40));
        list.add(new FiedValue(62, this.getMartial()));
        list.add(new FiedValue(66, this.getLoyalty()));
        list.add(new FiedValue(55, SpringUtils.getRoleService().getPetUpgradeNeedExp(this.getLevel())));
        list.add(new FiedValue(86, this.getIcon()));
        list.add(new FiedValue(104, this.getTotalLifeEffect()));
        list.add(new FiedValue(105, this.getTotalManaEffect()));
        list.add(new FiedValue(107, this.getTotalPhyEffect()));
        list.add(new FiedValue(108, this.getTotalMagEffect()));
        list.add(new FiedValue(106, this.getTotalSpeedEffect()));

        list.add(new FiedValue(110, 0));//penetrate
        list.add(new FiedValue(261, 0));//locked
        list.add(new FiedValue(271, 0));//recognize/recognized
        list.add(new FiedValue(262, 0));
        list.add(new FiedValue(121, 0));
        list.add(new FiedValue(122, 0));
        list.add(new FiedValue(265, this.getPhyRebuildLevel()));
        list.add(new FiedValue(266, this.getMagRebuildLevel()));
        list.add(new FiedValue(294, this.getItype()));
        list.add(new FiedValue(719, this.getPhyRebuildRate()));
        list.add(new FiedValue(720, this.getMagRebuildRate()));
        list.add(new FiedValue(800, this.getPhyRebuildAdd()));
        list.add(new FiedValue(801, this.getMagRebuildAdd()));

        list.add(new FiedValue(802, this.refineMap.getInt("life", 0)));
        list.add(new FiedValue(803, this.refineMap.getInt("mana", 0)));
        list.add(new FiedValue(804, this.refineMap.getInt("speed", 0)));
        list.add(new FiedValue(805, this.refineMap.getInt("phy", 0)));
        list.add(new FiedValue(806, this.refineMap.getInt("mag", 0)));




        list.add(new FiedValue(721, 0));//life_add_temp
        list.add(new FiedValue(722, 0));//mana_add_temp
        list.add(new FiedValue(723, 0));//phy_power_add_temp
        list.add(new FiedValue(724, 0));//mag_power_add_temp
        list.add(new FiedValue(725, 0));//speed_add_temp
        list.add(new FiedValue(726, 0));//def_add_temp

        list.add(new FiedValue(311, this.isLockexp() ? 1 : 0));
        list.add(new FiedValue(270, this.getLimitTime()));
        list.add(new FiedValue(205, this.getReqLevel()));
        list.add(new FiedValue(870, this.getEnchant()));
        list.add(new FiedValue(871, this.getEnchant_v()));
        list.add(new FiedValue(872, this.getEnchant_k()));

        list.add(new FiedValue(931, this.getEclosion()));
        list.add(new FiedValue(932, this.getEclosion_v()));
        list.add(new FiedValue(933, this.getEclosion_k()));
        list.add(new FiedValue(935, this.getEclosion_rank()));//0初阶1中阶2高阶
        //共生 ID
        list.add(new FiedValue(975, this.getGongSheng_pet_id()));


        //共生成长
        list.add(new FiedValue(1093, (int)this.gongShengEffect.getOrDefault("life", 0)));
        list.add(new FiedValue(1094, (int)this.gongShengEffect.getOrDefault("mana", 0)));
        list.add(new FiedValue(1095, (int)this.gongShengEffect.getOrDefault("speed", 0)));
        list.add(new FiedValue(1096, (int)this.gongShengEffect.getOrDefault("phy", 0)));
        list.add(new FiedValue(1097, (int)this.gongShengEffect.getOrDefault("mag", 0)));

        //培元信息
        list.add(new FiedValue(961, this.getPeiyuan_data_level()));
        list.add(new FiedValue(962, this.getPeiyuan_data_stage()));
        list.add(new FiedValue(964, this.getPeiyuan_data_state()));
//
//        if(this.getPeiyuan_add_info().containsKey("max_life")){
//            list.add(new FiedValue(1099, JSON.toJSON(this.getPeiyuan_add_info()).toString()));
//        }
//        list.add(new FiedValue(1098,  JSON.toJSON(this.getPetyuan_cur_state_info()).toString()));
//        list.add(new FiedValue(1101, this.getPeiyuan_attrib_count()));
//
//        list.add(new FiedValue(1101, this.getPeiyuan_attrib_count()));

        list.add(new FiedValue(879, ""));//evolve进化的名字?

        list.add(new FiedValue(232, this.getLifeEffect() - 40));
        list.add(new FiedValue(233, this.getManaEffect() - 40));
        list.add(new FiedValue(235, this.getSpeedEffect() - 40));
        list.add(new FiedValue(236, this.getPhyEffect() - 40));
        list.add(new FiedValue(237, this.getMagEffect() - 40));

        list.add(new FiedValue(315, 0));//extra_life_effect
        list.add(new FiedValue(316, 0));//extra_mana_effect
        list.add(new FiedValue(317, 0));//extra_mag_effect
        list.add(new FiedValue(318, 0));//extra_phy_effect
        list.add(new FiedValue(319, 0));//extra_speed_effect
        list.add(new FiedValue(320, morphEffect.getOrDefault("life_times", 0)));//morph_life_times  todo 幻化次数
        list.add(new FiedValue(321, morphEffect.getOrDefault("mana_times", 0)));//morph_mana_times
        list.add(new FiedValue(322, morphEffect.getOrDefault("speed_times", 0)));//morph_speed_times
        list.add(new FiedValue(323, morphEffect.getOrDefault("phy_times", 0)));//morph_phy_times
        list.add(new FiedValue(324, morphEffect.getOrDefault("mag_times", 0)));//morph_mag_times
        list.add(new FiedValue(325, morphEffect.getOrDefault("life_stat", 0)));//morph_life_stat todo 当前阶段幻化第几次
        list.add(new FiedValue(326, morphEffect.getOrDefault("mana_stat", 0)));//morph_mana_stat
        list.add(new FiedValue(327, morphEffect.getOrDefault("speed_stat", 0)));//morph_speed_stat
        list.add(new FiedValue(328, morphEffect.getOrDefault("phy_stat", 0)));//morph_phy_stat
        list.add(new FiedValue(329, morphEffect.getOrDefault("mag_stat", 0)));//morph_mag_stat

        list.add(new FiedValue(883, this.getMountTime()));//风灵丸时间

        int currTime = new Long(new Date().getTime() / 1000).intValue();
        int fenglingwanNum = (this.getMountTime() - currTime) / 86400 / 5;
        int moveSpeed = fenglingwanNum * 5;
        int rank = this.getRank();
        if (this.getRank() >=8 ){
            /*增加坐骑阶位*/
            if (role.getPetBox().getZuoqi().contains(24)) {
                rank = rank +16;
            } else if (role.getPetBox().getZuoqi().contains(21)) {
                rank = rank +13;
            }
            else if (role.getPetBox().getZuoqi().contains(18)) {
                rank = rank +10;
            }else if (role.getPetBox().getZuoqi().contains(15)) {
                rank = rank +7;
            }else if (role.getPetBox().getZuoqi().contains(13)){
                rank = rank +5;
            }else if (role.getPetBox().getZuoqi().contains(10)){
                rank = rank +2;
            }
/*            HunPoProp hunPoProp = SpringUtils.getBean(HunPoService.class).getHunPoProp(role);
            if (hunPoProp.getLevel() * 10 + hunPoProp.getLevelInner() >= 110) {
                rank = rank +7;
            }else if (role.getTotalCharge() >= 10000){
                rank = rank +5;
            }else if (role.getTotalCharge() >= 5000){
                rank = rank +2;
            }*/
        }
        if (moveSpeed > rank * 5) {
            moveSpeed = rank * 5;
        }
        list.add(new FiedValue(884, this.getMountTime() > currTime ? moveSpeed : 0));
        list.add(new FiedValue(885, rank));//坐骑阶数
        list.add(new FiedValue(888, 0));//merge_rate
        list.add(new FiedValue(886, role == null ? (byte) 0 : (role.isHideMount() ? (byte) 1 : (byte) 0)));//隐藏坐骑
        list.add(new FiedValue(887, 0));//deadline
        list.add(new FiedValue(890, 0));//顿悟次数
        list.add(new FiedValue(891, 0));//dunwu_rate 顿悟成功率?
        list.add(new FiedValue(892, 0));//pet_anger

        list.add(new FiedValue(3016, 0));//gm_attribs/max_life  GM属性?
        list.add(new FiedValue(3017, 0));//gm_attribs/max_mana  GM属性?
        list.add(new FiedValue(3020, 0));//gm_attribs/def  GM属性?
        list.add(new FiedValue(3021, 0));//gm_attribs/speed  GM属性?
        list.add(new FiedValue(3018, 0));//gm_attribs/phy_power  GM属性?
        list.add(new FiedValue(3019, 0));//gm_attribs/mag_power  GM属性?

        list.add(new FiedValue(920, phyPower));
        list.add(new FiedValue(921, magPower));
        list.add(new FiedValue(922, defense));

        list.add(new FiedValue(493, 3,this.getFight_cap()));

        list.add(new FiedValue(923, this.getIntimacy()));
        list.add(new FiedValue(306, this.getGid()));
        list.add(new FiedValue(267, this.getName()));//原始名字
        list.add(new FiedValue(176, this.getHostName()));//主人

        list.add(new FiedValue(953, this.getSpecial_icon()));
        if(this.getSpecial_icon() == 0){
            list.add(new FiedValue(954,0 ));
        }else{
            list.add(new FiedValue(954,1 ));
        }

        list.add(new FiedValue(466, this.getMonthMartial()));
        list.add(new FiedValue(467, this.getPrevMonthMartial()));
        list.add(new FiedValue(347, this.getFly()));
        list.add(new FiedValue(116, this.special_icon));

        Fuling fuling = SpringUtils.getFulingService().getFulingdata(role.getRoleId());
        if(fuling!=null){
            byte type = this.getZhenlingType();
            list.add(new FiedValue(1005,  type));//真灵类型
            if(type==1){
                list.add(new FiedValue(1006, fuling.getQinglong()));//真灵等级
            }else if(type==2){
                list.add(new FiedValue(1006, fuling.getZhuque()));//真灵等级
            }else if(type==3){
                list.add(new FiedValue(1006, fuling.getBaihu()));//真灵等级
            }else if(type==4){
                list.add(new FiedValue(1006, fuling.getXuanwu()));//真灵等级
            }
        }
        return basicField;
    }

    /**
     * 取宠物属性
     */
    @JsonIgnore
    @JSONField(serialize = false)
    public List<EquipField> getAllFields() {
        List<EquipField> list = new ArrayList<>();
        list.add(getFields());
        if (getItype() >=1) {
            list.add(SpringUtils.getPetService().getMountAttrib(this));
        }
        List<EquipField> stoneFields = SpringUtils.getBean(PetStoneService.class).getStoneExtraFields(this);
        if (stoneFields != null && stoneFields.size() >= 1) {
            list.addAll(stoneFields);
        }

        return list;
    }

    /**
     * 取宠物亲密增加的额外属性
     */
    public NutMap getExtraAttr() {
        NutMap extra = NutMap.NEW();
        int intimacy = this.getIntimacy();
        if (this.getType() == 2) {
            /* 普通*/
            if (intimacy >= 500000) {
                extra.setv("attack", 0.15).setv("def", 0.2).setv("stunt", 32).setv("double", 34).setv("doubleHit", 5);
            } else if (intimacy >= 300000) {
                extra.setv("attack", 0.1).setv("def", 0.15).setv("stunt", 24).setv("double", 26).setv("doubleHit", 4);
            } else if (intimacy >= 100000) {
                extra.setv("attack", 0.06).setv("def", 0.1).setv("stunt", 16).setv("double", 18).setv("doubleHit", 3);
            } else {
                extra.setv("attack", 0.03).setv("def", 0.05).setv("stunt", 8).setv("double", 10).setv("doubleHit", 2);
            }
        } else {
            /* 变异*/
            if (intimacy >= 5000000) {
                extra.setv("attack", 0.30).setv("def", 0.35).setv("stunt", 50).setv("double", 50).setv("doubleHit", 8);
            } else if (intimacy >= 2000000) {
                extra.setv("attack", 0.25).setv("def", 0.30).setv("stunt", 50).setv("double", 50).setv("doubleHit", 7);
            } else if (intimacy >= 1000000) {
                extra.setv("attack", 0.20).setv("def", 0.25).setv("stunt", 50).setv("double", 50).setv("doubleHit", 6);
            } else if (intimacy >= 500000) {
                extra.setv("attack", 0.15).setv("def", 0.2).setv("stunt", 40).setv("double", 40).setv("doubleHit", 5);
            } else if (intimacy >= 300000) {
                extra.setv("attack", 0.10).setv("def", 0.15).setv("stunt", 30).setv("double", 30).setv("doubleHit", 4);
            } else if (intimacy >= 100000) {
                extra.setv("attack", 0.06).setv("def", 0.10).setv("stunt", 20).setv("double", 20).setv("doubleHit", 3);
            } else {
                extra.setv("attack", 0.03).setv("def", 0.05).setv("stunt", 10).setv("double", 10).setv("doubleHit", 2);
            }
        }
        return extra;
    }

    /**
     * 根据忠诚度判断能否参战
     */
    public boolean canJoinFight() {
        Random random = new Random();
        int index = random.nextInt(100) + 1;
        if (longevity <=0){
            return false;
        }
        /**如果随机值大于忠诚度 则宠物不会参战*/
        if (loyalty > 70) {
            return true;
        }
        return index > loyalty;
    }
    /*附灵*/
    @Comment("真灵附身类型")
    private byte zhenlingType;

    @Column
    private double qinglong = 1.0;

    public double getQinglong() {
        return this.qinglong;
    }

    public void setQinglong(double qinglong) {
        this.qinglong = qinglong;
    }

    @Column
    private double baihu = 1.0;

    public double getBaihu() {
        return this.baihu;
    }

    public void setBaihu(double baihu) {
        this.baihu = baihu;
    }

    @Column
    private double zhuque = 1.0;

    public double getZhuque() {
        return this.zhuque;
    }

    public void setZhuque(double zhuque) {
        this.zhuque = zhuque;
    }

    @Column
    private double xuanwu = 1.0;

    public double getXuanwu() {
        return this.xuanwu;
    }

    public void setXuanwu(double xuanwu) {
        this.xuanwu = xuanwu;
    }
    /*洛书*/
    @JsonIgnore
    @JSONField(serialize = false)
    public int getluoshuMagpower() {
        Role role = SpringUtils.getRoleService().getPlayerBy(this.hostId);
        if(role==null){
            System.out.println("---------------");
        }
        int magpower = role.getLuoshuMagpower();
        return magpower;
    }
    @JsonIgnore
    @JSONField(serialize = false)
    public int getluoshuPhypower() {
        Role role = SpringUtils.getRoleService().getPlayerBy(this.hostId);
        int phypower = role.getLuoshumPhypower();
        return phypower;
    }
    @JsonIgnore
    @JSONField(serialize = false)
    public int getluoshuSpeed() {
        Role role = SpringUtils.getRoleService().getPlayerBy(this.hostId);
        int speed = role.getLuoshuSpeed();
        return speed;
    }
    @JsonIgnore
    @JSONField(serialize = false)
    public int getluoshuDefense() {
        Role role = SpringUtils.getRoleService().getPlayerBy(this.hostId);
        int defense = role.getLuoshuDefense();
        return defense;
    }
}
